/**
 * $Revision: 1.2 $
 * $Date: 2007/06/09 12:13:06 $
 *
 * Copyright (C) 1999-2005 Jive Software. All rights reserved.
 * This software is the proprietary information of Jive Software. Use is subject to license terms.
 */

package com.regal.packet;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.jivesoftware.smack.packet.PacketExtension;

/**
 *
 */
public class NewsPush implements PacketExtension {
	/**
     * Element name of the packet extension.
     */
    public static final String ELEMENT_NAME = "query";

    /**
     * Namespace of the packet extension.
     */
    public static final String NAMESPACE = "jabber:message:news_push";

    private final List<NewsItem> newsItems = new ArrayList<NewsItem>();
    
    
    public NewsPush() {
       
    }
  
    public String getElementName() {
        return ELEMENT_NAME;
    }

    public String getNamespace() {
        return NAMESPACE;
    }
    
    public void addNewsItem(NewsItem item) {    	
    	synchronized (newsItems) {
    		newsItems.add(item);
        }    	
    }
    
    public int getNewsItemCount() {
        synchronized (newsItems) {
            return newsItems.size();
        }
    }
    
    public Collection<NewsItem> getNewsItems() {
        synchronized (newsItems) {
            return Collections.unmodifiableList(new ArrayList<NewsItem>(newsItems));
        }
    }
 
    public String toXML() {
        StringBuffer buf = new StringBuffer();
       
        return buf.toString();
    }
    
    
    
    /**
     * A News item, which consists of a title, url.
     */
    public static class NewsItem {

        private String title;
        private String url;
        
        /**
         * Creates a new urlNews item.
         *
         * @param user the title.
         * @param name the url.
         */
        public NewsItem(String title, String url) {
            this.title = title;
            this.url = url;
        }

        /**
         * Returns the title.
         *
         * @return the title.
         */
        public String getTitle() {
            return title;
        }

        /**
         * Returns the url.
         *
         * @return the url.
         */
        public String getUrl() {
            return url;
        }

        /**
         * Sets the title.
         *
         * @param title.
         */
        public void setTitle(String title) {
            this.title = title;
        }
    
        /**
         * Sets the title.
         *
         * @param title.
         */
        public void setUrl(String url) {
            this.url = url;
        }

    }
}